package com.lulin.mall.coupon.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lulin.common.utils.PageUtils;
import com.lulin.common.utils.Query;

import com.lulin.mall.coupon.dao.SeckillSkuRelationDao;
import com.lulin.mall.coupon.entity.SeckillSkuRelationEntity;
import com.lulin.mall.coupon.service.SeckillSkuRelationService;


@Service("seckillSkuRelationService")
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationDao, SeckillSkuRelationEntity> implements SeckillSkuRelationService {

    /**
     * 每日秒杀的关联秒杀商品分页查询
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<SeckillSkuRelationEntity> queryWrapper = new QueryWrapper<>();
        //活动场次id
        String promotionSessionId = (String) params.get("promotionSessionId");
        //关键字没有意义，这里用sku_id
        String key = (String) params.get("key");

        //查询条件
        queryWrapper.eq(StringUtils.isNotBlank(promotionSessionId), "promotion_session_id", promotionSessionId)
                .eq(StringUtils.isNotBlank(key), "sku_id", key);

        IPage<SeckillSkuRelationEntity> page = this.page(
                new Query<SeckillSkuRelationEntity>().getPage(params), queryWrapper
        );

        return new PageUtils(page);
    }
}
